package org.mat.ipaas.ucenter.bff.admin.modules.system;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysUserRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysUserAgentDTO;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysUserDTO;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysUserDepartDTO;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysUserRoleDTO;
import org.mat.ipaas.ucenter.service.dto.system.model.DepartIdModelDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.SysDepartUsersVODTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.SysUserRoleVODTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.lowapp.DepartAndUserInfoDTO;
import org.mat.ipaas.ucenter.service.dto.system.vo.lowapp.UpdateDepartInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @Author scott
 * @since 2018-12-20
 */
@Slf4j
@RestController
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private SysUserRestAPI sysUserRestAPI;

    /**
     * 获取租户下用户数据（支持租户隔离）
     *
     * @param sysUserDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MatApiResponse<?> queryPageList(@SpringQueryMap SysUserDTO sysUserDTO,
                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.queryPageList(sysUserDTO, pageNo, pageSize);
        return matApiResponse;
    }

    /**
     * 获取系统用户数据（查询全部用户，不做租户隔离）
     *
     * @param sysUserDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    //@RequiresPermissions("system:user:listAll")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public MatApiResponse<?> queryAllPageList(SysUserDTO sysUserDTO,
                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.queryAllPageList(sysUserDTO, pageNo, pageSize);
        return matApiResponse;
    }

    //@RequiresPermissions("system:user:add")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public MatApiResponse<SysUserDTO> add(@RequestBody JSONObject jsonObject) {
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.add(jsonObject);
        return matApiResponse;
    }

    //@RequiresPermissions("system:user:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<SysUserDTO> edit(@RequestBody JSONObject jsonObject) {
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.edit(jsonObject);
        return matApiResponse;
    }

    /**
     * 删除用户
     */
    //@RequiresPermissions("system:user:delete")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public MatApiResponse<?> delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除用户
     */
    //@RequiresPermissions("system:user:deleteBatch")
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    public MatApiResponse<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 冻结&解冻用户
     *
     * @param jsonObject
     * @return
     */
    //@RequiresPermissions("system:user:frozenBatch")
    @RequestMapping(value = "/frozenBatch", method = RequestMethod.PUT)
    public MatApiResponse<SysUserDTO> frozenBatch(@RequestBody JSONObject jsonObject) {
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.frozenBatch(jsonObject);
        return matApiResponse;
    }

    //@RequiresPermissions("system:user:queryById")
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public MatApiResponse<SysUserDTO> queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.queryById(id);
        return matApiResponse;
    }

    //@RequiresPermissions("system:user:queryUserRole")
    @RequestMapping(value = "/queryUserRole", method = RequestMethod.GET)
    public MatApiResponse<List<String>> queryUserRole(@RequestParam(name = "userid", required = true) String userid) {
        MatApiResponse<List<String>> matApiResponse = sysUserRestAPI.queryUserRole(userid);
        return matApiResponse;
    }


    /**
     * 校验用户账号是否唯一<br>
     * 可以校验其他 需要检验什么就传什么。。。
     *
     * @param sysUserDTO
     * @return
     */
    @RequestMapping(value = "/checkOnlyUser", method = RequestMethod.GET)
    public MatApiResponse<Boolean> checkOnlyUser(SysUserDTO sysUserDTO) {
        MatApiResponse<Boolean> matApiResponse = sysUserRestAPI.checkOnlyUser(sysUserDTO);
        return matApiResponse;
    }

    /**
     * 修改密码
     */
    //@RequiresPermissions("system:user:changepwd")
    @RequestMapping(value = "/changePassword", method = RequestMethod.PUT)
    public MatApiResponse<?> changePassword(@RequestBody SysUserDTO sysUserDTO) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.changePassword(sysUserDTO);
        return matApiResponse;
    }

    /**
     * 查询指定用户和部门关联的数据
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/userDepartList", method = RequestMethod.GET)
    public MatApiResponse<List<DepartIdModelDTO>> getUserDepartsList(@RequestParam(name = "userId", required = true) String userId) {
        MatApiResponse<List<DepartIdModelDTO>> matApiResponse = sysUserRestAPI.getUserDepartsList(userId);
        return matApiResponse;
    }

    /**
     * 生成在添加用户情况下没有主键的问题,返回给前端,根据该id绑定部门数据
     *
     * @return
     */
    @RequestMapping(value = "/generateUserId", method = RequestMethod.GET)
    public MatApiResponse<String> generateUserId() {
        MatApiResponse<String> matApiResponse = sysUserRestAPI.generateUserId();
        return matApiResponse;
    }

    /**
     * 根据部门id查询用户信息
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/queryUserByDepId", method = RequestMethod.GET)
    public MatApiResponse<List<SysUserDTO>> queryUserByDepId(@RequestParam(name = "id", required = true) String id, @RequestParam(name = "realname", required = false) String realname) {
        MatApiResponse<List<SysUserDTO>> matApiResponse = sysUserRestAPI.queryUserByDepId(id, realname);
        return matApiResponse;
    }

    /**
     * 用户选择组件 专用  根据用户账号或部门分页查询
     *
     * @param departId
     * @param username
     * @return
     */
    @RequestMapping(value = "/queryUserComponentData", method = RequestMethod.GET)
    public MatApiResponse<IPage<SysUserDTO>> queryUserComponentData(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "departId", required = false) String departId,
            @RequestParam(name = "realname", required = false) String realname,
            @RequestParam(name = "username", required = false) String username,
            @RequestParam(name = "id", required = false) String id) {
        MatApiResponse<IPage<SysUserDTO>> matApiResponse = sysUserRestAPI.queryUserComponentData(pageNo, pageSize, departId, realname, username, id);
        return matApiResponse;
    }

    /**
     * 导出excel
     *
     * @param sysUserDTO
     */
    //@RequiresPermissions("system:user:export")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(SysUserDTO sysUserDTO) {
        ModelAndView modelAndView = sysUserRestAPI.exportXls(sysUserDTO);
        return modelAndView;
    }

    /**
     * 通过excel导入数据
     *
     * @return
     */
    //@RequiresPermissions("system:user:import")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public MatApiResponse<?> importExcel() throws IOException {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.importExcel();
        return matApiResponse;
    }

    /**
     * @param userIds
     * @return
     * @功能：根据id 批量查询
     */
    @RequestMapping(value = "/queryByIds", method = RequestMethod.GET)
    public MatApiResponse<List<SysUserDTO>> queryByIds(@RequestParam String userIds) {
        MatApiResponse<List<SysUserDTO>> matApiResponse = sysUserRestAPI.queryByIds(userIds);
        return matApiResponse;
    }


    /**
     * @param userNames
     * @return
     * @功能：根据id 批量查询
     */
    @RequestMapping(value = "/queryByNames", method = RequestMethod.GET)
    public MatApiResponse<List<SysUserDTO>> queryByNames(@RequestParam String userNames) {
        MatApiResponse<List<SysUserDTO>> matApiResponse = sysUserRestAPI.queryByNames(userNames);
        return matApiResponse;
    }

    /**
     * 首页用户重置密码
     */
    //@RequiresPermissions("system:user:updatepwd")
    @RequestMapping(value = "/updatePassword", method = RequestMethod.PUT)
    public MatApiResponse<?> updatePassword(@RequestBody JSONObject json) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.updatePassword(json);
        return matApiResponse;
    }

    @RequestMapping(value = "/userRoleList", method = RequestMethod.GET)
    public MatApiResponse<Page<SysUserDTO>> userRoleList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<Page<SysUserDTO>> matApiResponse = sysUserRestAPI.userRoleList(pageNo, pageSize);
        return matApiResponse;
    }

    /**
     * 给指定角色添加用户
     *
     * @param
     * @return
     */
    //@RequiresPermissions("system:user:addUserRole")
    @RequestMapping(value = "/addSysUserRole", method = RequestMethod.POST)
    public MatApiResponse<String> addSysUserRole(@RequestBody SysUserRoleVODTO sysUserRoleVODTO) {
        MatApiResponse<String> matApiResponse = sysUserRestAPI.addSysUserRole(sysUserRoleVODTO);
        return matApiResponse;
    }

    /**
     * 删除指定角色的用户关系
     *
     * @param
     * @return
     */
    //@RequiresPermissions("system:user:deleteRole")
    @RequestMapping(value = "/deleteUserRole", method = RequestMethod.DELETE)
    public MatApiResponse<SysUserRoleDTO> deleteUserRole(@RequestParam(name = "roleId") String roleId,
                                                         @RequestParam(name = "userId", required = true) String userId
    ) {
        MatApiResponse<SysUserRoleDTO> matApiResponse = sysUserRestAPI.deleteUserRole(roleId, userId);
        return matApiResponse;
    }

    /**
     * 批量删除指定角色的用户关系
     *
     * @param
     * @return
     */
    //@RequiresPermissions("system:user:deleteRoleBatch")
    @RequestMapping(value = "/deleteUserRoleBatch", method = RequestMethod.DELETE)
    public MatApiResponse<SysUserRoleDTO> deleteUserRoleBatch(
            @RequestParam(name = "roleId") String roleId,
            @RequestParam(name = "userIds", required = true) String userIds) {
        MatApiResponse<SysUserRoleDTO> matApiResponse = sysUserRestAPI.deleteUserRoleBatch(roleId, userIds);
        return matApiResponse;
    }

    /**
     * 部门用户列表
     */
    @RequestMapping(value = "/departUserList", method = RequestMethod.GET)
    public MatApiResponse<Page<SysUserDTO>> departUserList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<Page<SysUserDTO>> matApiResponse = sysUserRestAPI.departUserList(pageNo, pageSize);
        return matApiResponse;
    }


    /**
     * 根据 orgCode 查询用户，包括子部门下的用户
     * 若某个用户包含多个部门，则会显示多条记录，可自行处理成单条记录
     */
    @GetMapping("/queryByOrgCode")
    public MatApiResponse<?> queryByDepartId(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "orgCode") String orgCode,
            SysUserDTO sysUserDTO
    ) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.queryByDepartId(pageNo, pageSize, orgCode, sysUserDTO);
        return matApiResponse;
    }

    /**
     * 根据 orgCode 查询用户，包括子部门下的用户
     * 针对通讯录模块做的接口，将多个部门的用户合并成一条记录，并转成对前端友好的格式
     */
    @GetMapping("/queryByOrgCodeForAddressList")
    public MatApiResponse<?> queryByOrgCodeForAddressList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "orgCode", required = false) String orgCode,
            SysUserDTO sysUserDTO
    ) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.queryByOrgCodeForAddressList(pageNo, pageSize, orgCode, sysUserDTO);
        return matApiResponse;
    }

    /**
     * 给指定部门添加对应的用户
     */
    //@RequiresPermissions("system:user:editDepartWithUser")
    @RequestMapping(value = "/editSysDepartWithUser", method = RequestMethod.POST)
    public MatApiResponse<String> editSysDepartWithUser(@RequestBody SysDepartUsersVODTO sysDepartUsersVODTO) {
        MatApiResponse<String> matApiResponse = sysUserRestAPI.editSysDepartWithUser(sysDepartUsersVODTO);
        return matApiResponse;
    }

    /**
     * 删除指定机构的用户关系
     */
    //@RequiresPermissions("system:user:deleteUserInDepart")
    @RequestMapping(value = "/deleteUserInDepart", method = RequestMethod.DELETE)
    public MatApiResponse<SysUserDepartDTO> deleteUserInDepart(@RequestParam(name = "depId") String depId,
                                                               @RequestParam(name = "userId", required = true) String userId
    ) {
        MatApiResponse<SysUserDepartDTO> matApiResponse = sysUserRestAPI.deleteUserInDepart(depId, userId);
        return matApiResponse;
    }

    /**
     * 批量删除指定机构的用户关系
     */
    //@RequiresPermissions("system:user:deleteUserInDepartBatch")
    @RequestMapping(value = "/deleteUserInDepartBatch", method = RequestMethod.DELETE)
    public MatApiResponse<SysUserDepartDTO> deleteUserInDepartBatch(
            @RequestParam(name = "depId") String depId,
            @RequestParam(name = "userIds", required = true) String userIds) {
        MatApiResponse<SysUserDepartDTO> matApiResponse = sysUserRestAPI.deleteUserInDepartBatch(depId, userIds);
        return matApiResponse;
    }

    /**
     * 查询当前用户的所有部门/当前部门编码
     *
     * @return
     */
    @RequestMapping(value = "/getCurrentUserDeparts", method = RequestMethod.GET)
    public MatApiResponse<Map<String, Object>> getCurrentUserDeparts() {
        MatApiResponse<Map<String, Object>> matApiResponse = sysUserRestAPI.getCurrentUserDeparts();
        return matApiResponse;
    }


    /**
     * 用户注册接口
     *
     * @param jsonObject
     * @param sysUserDTO
     * @return
     */
    @PostMapping("/register")
    public MatApiResponse<JSONObject> userRegister(@RequestBody JSONObject jsonObject, SysUserDTO sysUserDTO) {
        MatApiResponse<JSONObject> matApiResponse = sysUserRestAPI.userRegister(jsonObject, sysUserDTO);
        return matApiResponse;
    }

    /**
     * 用户手机号验证
     */
    @PostMapping("/phoneVerification")
    public MatApiResponse<Map<String, String>> phoneVerification(@RequestBody JSONObject jsonObject) {
        MatApiResponse<Map<String, String>> matApiResponse = sysUserRestAPI.phoneVerification(jsonObject);
        return matApiResponse;
    }

    /**
     * 用户更改密码
     */
    @GetMapping("/passwordChange")
    public MatApiResponse<SysUserDTO> passwordChange(@RequestParam(name = "username") String username,
                                                     @RequestParam(name = "password") String password,
                                                     @RequestParam(name = "smscode") String smscode,
                                                     @RequestParam(name = "phone") String phone) {
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.passwordChange(username, password, smscode, phone);
        return matApiResponse;
    }


    /**
     * 根据TOKEN获取用户的部分信息（返回的数据是可供表单设计器使用的数据）
     *
     * @return
     */
    @GetMapping("/getUserSectionInfoByToken")
    public MatApiResponse<?> getUserSectionInfoByToken(HttpServletRequest request, @RequestParam(name = "token", required = false) String token) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse<?> matApiResponse = sysUserRestAPI.getUserSectionInfoByToken(accessToken, token);
        return matApiResponse;
    }

    /**
     * 【APP端接口】获取用户列表  根据用户名和真实名 模糊匹配
     *
     * @param keyword
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/appUserList")
    public MatApiResponse<?> appUserList(@RequestParam(name = "keyword", required = false) String keyword,
                                         @RequestParam(name = "username", required = false) String username,
                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                         @RequestParam(name = "syncFlow", required = false) String syncFlow) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.appUserList(keyword, username, pageNo, pageSize, syncFlow);
        return matApiResponse;
    }

    /**
     * 获取被逻辑删除的用户列表，无分页
     *
     * @return logicDeletedUserList
     */
    @GetMapping("/recycleBin")
    public MatApiResponse getRecycleBin() {
        MatApiResponse matApiResponse = sysUserRestAPI.getRecycleBin();
        return matApiResponse;
    }

    /**
     * 还原被逻辑删除的用户
     *
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/putRecycleBin", method = RequestMethod.PUT)
    public MatApiResponse putRecycleBin(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse matApiResponse = sysUserRestAPI.putRecycleBin(accessToken, jsonObject);
        return matApiResponse;
    }

    /**
     * 彻底删除用户
     *
     * @param userIds 被删除的用户ID，多个id用半角逗号分割
     * @return
     */
    //@RequiresPermissions("system:user:deleteRecycleBin")
    @RequestMapping(value = "/deleteRecycleBin", method = RequestMethod.DELETE)
    public MatApiResponse deleteRecycleBin(@RequestParam("userIds") String userIds) {
        MatApiResponse matApiResponse = sysUserRestAPI.deleteRecycleBin(userIds);
        return matApiResponse;
    }


    /**
     * 移动端修改用户信息
     *
     * @param jsonObject
     * @return
     */
    @RequiresRoles({"admin"})
    @RequestMapping(value = "/appEdit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<SysUserDTO> appEdit(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.appEdit(accessToken, jsonObject);
        return matApiResponse;
    }

    /**
     * 移动端保存设备信息
     *
     * @param clientId
     * @return
     */
    @RequestMapping(value = "/saveClientId", method = RequestMethod.GET)
    public MatApiResponse<SysUserDTO> saveClientId(HttpServletRequest request, @RequestParam("clientId") String clientId) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.saveClientId(accessToken, clientId);
        return matApiResponse;
    }

    /**
     * 根据userid获取用户信息和部门员工信息
     *
     * @return Result
     */
    @GetMapping("/queryChildrenByUsername")
    public MatApiResponse queryChildrenByUsername(@RequestParam("userId") String userId) {
        MatApiResponse matApiResponse = sysUserRestAPI.queryChildrenByUsername(userId);
        return matApiResponse;
    }

    /**
     * 移动端查询部门用户信息
     *
     * @param departId
     * @return
     */
    @GetMapping("/appQueryByDepartId")
    public MatApiResponse<List<SysUserDTO>> appQueryByDepartId(@RequestParam(name = "departId", required = false) String departId) {
        MatApiResponse<List<SysUserDTO>> matApiResponse = sysUserRestAPI.appQueryByDepartId(departId);
        return matApiResponse;
    }

    /**
     * 移动端查询用户信息(通过用户名模糊查询)
     *
     * @param keyword
     * @return
     */
    @GetMapping("/appQueryUser")
    public MatApiResponse<List<SysUserDTO>> appQueryUser(@RequestParam(name = "keyword", required = false) String keyword,
                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<List<SysUserDTO>> matApiResponse = sysUserRestAPI.appQueryUser(keyword, pageNo, pageSize);
        return matApiResponse;
    }

    /**
     * 根据用户名修改手机号[该方法未使用]
     *
     * @param json
     * @return
     */
    @RequestMapping(value = "/updateMobile", method = RequestMethod.PUT)
    public MatApiResponse<?> changMobile(@RequestBody JSONObject json, HttpServletRequest request) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse<?> matApiResponse = sysUserRestAPI.changMobile(accessToken, json);
        return matApiResponse;
    }


    /**
     * 根据对象里面的属性值作in查询 属性可能会变 用户组件用到
     *
     * @param sysUserDTO
     * @return
     */
    @GetMapping("/getMultiUser")
    public List<SysUserDTO> getMultiUser(SysUserDTO sysUserDTO) {
        List<SysUserDTO> multiUser = sysUserRestAPI.getMultiUser(sysUserDTO);
        return multiUser;
    }

    /**
     * 聊天 创建聊天组件专用  根据用户账号、用户姓名、部门id分页查询
     *
     * @param departId 部门id
     * @param keyword  搜索值
     * @return
     */
    @GetMapping(value = "/getUserInformation")
    public MatApiResponse<IPage<SysUserDTO>> getUserInformation(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "departId", required = false) String departId,
            @RequestParam(name = "keyword", required = false) String keyword) {
        MatApiResponse<IPage<SysUserDTO>> matApiResponse = sysUserRestAPI.getUserInformation(pageNo, pageSize, departId, keyword);
        return matApiResponse;
    }

    /**
     * 简版流程用户选择组件
     *
     * @param departId 部门id
     * @param roleId   角色id
     * @param keyword  搜索值
     * @return
     */
    @GetMapping(value = "/selectUserList")
    public MatApiResponse<IPage<SysUserDTO>> selectUserList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "departId", required = false) String departId,
            @RequestParam(name = "roleId", required = false) String roleId,
            @RequestParam(name = "keyword", required = false) String keyword) {
        MatApiResponse<IPage<SysUserDTO>> matApiResponse = sysUserRestAPI.selectUserList(pageNo, pageSize, departId, roleId, keyword);
        return matApiResponse;
    }

    /**
     * 用户离职(新增代理人和用户状态变更操作)【低代码应用专用接口】
     *
     * @param sysUserAgentDTO
     * @return
     */
    @PutMapping("/userQuitAgent")
    public MatApiResponse<String> userQuitAgent(@RequestBody SysUserAgentDTO sysUserAgentDTO) {
        MatApiResponse<String> matApiResponse = sysUserRestAPI.userQuitAgent(sysUserAgentDTO);
        return matApiResponse;
    }

    /**
     * 获取被逻辑删除的用户列表，无分页【低代码应用专用接口】
     *
     * @return List<SysUserDTO>
     */
    @GetMapping("/getQuitList")
    public MatApiResponse<List<SysUserDTO>> getQuitList(HttpServletRequest req) {
        MatApiResponse<List<SysUserDTO>> matApiResponse = sysUserRestAPI.getQuitList(req);
        return matApiResponse;
    }

    /**
     * 更新刪除状态和离职状态【低代码应用专用接口】
     *
     * @param jsonObject
     * @return Result<String>
     */
    @PutMapping("/putCancelQuit")
    public MatApiResponse<String> putCancelQuit(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
        MatApiResponse<String> matApiResponse = sysUserRestAPI.putCancelQuit(jsonObject, request);
        return matApiResponse;
    }

    /**
     * 获取用户信息(vue3用户设置专用)【低代码应用专用接口】
     *
     * @return
     */
    @GetMapping("/login/setting/getUserData")
    public MatApiResponse<SysUserDTO> getUserData(HttpServletRequest request) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.getUserData(accessToken);
        return matApiResponse;
    }

    /**
     * 用户编辑(vue3用户设置专用)【低代码应用专用接口】
     *
     * @param sysUserDTO
     * @return
     */
    @PostMapping("/login/setting/userEdit")
    //@RequiresPermissions("system:user:setting:edit")
    public MatApiResponse<String> userEdit(@RequestBody SysUserDTO sysUserDTO, HttpServletRequest request) {
        String accessToken = request.getHeader("X-Access-Token");
        MatApiResponse<String> matApiResponse = sysUserRestAPI.userEdit(accessToken, sysUserDTO);
        return matApiResponse;
    }

    /**
     * 批量修改 【low-app】
     *
     * @param jsonObject
     * @return
     */
    @PutMapping("/batchEditUsers")
    public MatApiResponse<SysUserDTO> batchEditUsers(@RequestBody JSONObject jsonObject) {
        MatApiResponse<SysUserDTO> matApiResponse = sysUserRestAPI.batchEditUsers(jsonObject);
        return matApiResponse;
    }

    /**
     * 根据关键词搜索部门和用户【low-app】
     *
     * @param keyword
     * @return
     */
    @GetMapping("/searchByKeyword")
    public MatApiResponse<DepartAndUserInfoDTO> searchByKeyword(@RequestParam(name = "keyword", required = false) String keyword) {
        MatApiResponse<DepartAndUserInfoDTO> matApiResponse = sysUserRestAPI.searchByKeyword(keyword);
        return matApiResponse;
    }

    /**
     * 编辑部门前获取部门相关信息 【low-app】
     *
     * @param id
     * @return
     */
    @GetMapping("/getUpdateDepartInfo")
    public MatApiResponse<UpdateDepartInfoDTO> getUpdateDepartInfo(@RequestParam(name = "id", required = false) String id) {
        MatApiResponse<UpdateDepartInfoDTO> matApiResponse = sysUserRestAPI.getUpdateDepartInfo(id);
        return matApiResponse;
    }

    /**
     * 编辑部门 【low-app】
     *
     * @param updateDepartInfoDTO
     * @return
     */
    @PutMapping("/doUpdateDepartInfo")
    public MatApiResponse<?> doUpdateDepartInfo(@RequestBody UpdateDepartInfoDTO updateDepartInfoDTO) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.doUpdateDepartInfo(updateDepartInfoDTO);
        return matApiResponse;
    }

    /**
     * 设置负责人 取消负责人
     *
     * @param json
     * @return
     */
    @PutMapping("/changeDepartChargePerson")
    public MatApiResponse<?> changeDepartChargePerson(@RequestBody JSONObject json) {
        MatApiResponse<?> matApiResponse = sysUserRestAPI.changeDepartChargePerson(json);
        return matApiResponse;
    }

    /**
     * 修改租户下的用户【低代码应用专用接口】
     *
     * @param sysUserDTO
     * @return
     */
    @RequestMapping(value = "/editTenantUser", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<String> editTenantUser(@RequestBody SysUserDTO sysUserDTO) {
        MatApiResponse<String> matApiResponse = sysUserRestAPI.editTenantUser(sysUserDTO);
        return matApiResponse;
    }
}
